package com.ecoolex.hotel.saas.api.graphql;

import com.ecoolex.framework.common.pojo.Page;
import com.ecoolex.framework.common.pojo.Pagination;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.QueryField;
import com.ecoolex.framework.web.api.graphql2.annotation.Source;
import com.ecoolex.framework.web.api.graphql2.annotation.TypeField;
import com.ecoolex.hotel.saas.entity.Activity;
import com.ecoolex.hotel.saas.entity.ActivityStore;
import com.ecoolex.hotel.saas.entity.Store;
import com.ecoolex.hotel.saas.ws.ActivityService;
import com.ecoolex.hotel.saas.ws.StoreService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.lang.NonNull;

import java.util.List;
import java.util.stream.Collectors;

@GraphQL2Module(type = GraphQL2Module.Type.User, description = "商圈活动")
public class ActivityGraphql {

    @Reference
    private ActivityService activityService;

    @Reference
    private StoreService storeService;

    @TypeField(type = ActivityStore.class, field = "store", description = "商户")
    public Store store(@Source ActivityStore source){
        return storeService.getStore(source.getStoreId());
    }

    @TypeField(type = Activity.class, field = "storeList", description = "商户")
    public List<Store> storeList(@Source Activity source, Integer size){
        List<ActivityStore> list = activityService.queryActivityStore(source.getActivityId(), size);
        return list.stream().map(activityStore -> storeService.getStore(activityStore.getStoreId())).collect(Collectors.toList());
    }

    @QueryField(field = "activity", description = "商圈活动详情")
    public Activity get(@NonNull Integer activityId){
        return activityService.get(activityId);
    }

    @QueryField(field = "activityList", description = "商圈活动列表")
    public Pagination<Activity> queryActivity(@NonNull Integer storeId, @NonNull Page page){
        return  activityService.queryByShowStoreId(storeId, page);
    }

    @QueryField(field = "activityStore", description = "商圈活动关联商户详情")
    public ActivityStore getActivityStore(@NonNull Integer id){
        return activityService.getActivityStore(id);
    }

    @QueryField(field = "activityStoreList", description = "商圈活动关联商户列表")
    public Pagination<ActivityStore> query(@NonNull Integer activityId, @NonNull Page page){
        return activityService.queryActivityStore(null,activityId,page);
    }
}
